<?php
if(!isset($_SESSION))
{
	session_start();
}
?>
<link	href="css/style.css" rel="stylesheet" type="text/css" />
<?php
$lang = $_SESSION['lang'];
if (empty($lang) || $lang == "EN") {
	include "../value/value_en.php";
} else if($lang == "VN") {
	include "../value/value_vn.php";
}
else {
	include "../value/value_kr.php";
}
include("content_salary/sa_funcs.php");
$mthu=array();
$mthu[0]='<font color="red" ><b>'.$l_vday_chunhat.'</b></font>';
$mthu[1]=$l_vday_thuhai;
$mthu[2]=$l_vday_thuba;
$mthu[3]=$l_vday_thutu;
$mthu[4]=$l_vday_thunam;
$mthu[5]=$l_vday_thusau;
$mthu[6]='<font color="red" ><b>'.$l_vday_thubay.'</b></font>';
$mthu[7]=" ";

$mthang=date('Y-m-d');
$ktdate=getdate(strtotime($mthang));
if(isset($_REQUEST['months'])){
	$_REQUEST['months']=$_REQUEST['months'];
}else{
	$_REQUEST['months']=$ktdate[mon];
}
if(isset($_REQUEST['years'])){
	$_REQUEST['years']=$_REQUEST['years'];
}else{
	$_REQUEST['years']=$ktdate[year];
}
?>
<script type="text/javascript">
function view(){
	var enam = document.getElementById("years");
	var nam = enam.options[enam.selectedIndex].value;
	var ethang = document.getElementById("months");
	var thang = ethang.options[ethang.selectedIndex].value;
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}else{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function(){
											var body = document.getElementById('viewbody');
											body.setAttribute('style','opacity:.5; position:relative;cursor: wait;  ');
											
											var d=document.createElement('div');
											d.setAttribute('style','display: block;visibility: visible; position: absolute;  z-index: 999; top: 0px; left: 0px; width: 105%; height: 105%; text-align: center;  filter: alpha(opacity=5); opacity: 0.5; ');
											
											var image=document.createElement('img');
											image.setAttribute('src','images/loading1.gif');
											image.setAttribute('style','position:absolute; left:0px; top:0px; right:0; bottom:0; margin:auto');
											
											d.appendChild(image);
											
										    body.appendChild(d);	
										    
										  if (xmlhttp.readyState==4 && xmlhttp.status==200){
										    	document.getElementById("viewbody").innerHTML=xmlhttp.responseText;
										    	document.getElementById('viewbody').setAttribute('style','opacity:1; position:relative;');
										  }
									  }
	xmlhttp.open("GET","ajax/salary/user_sa_search_chamcong.php?years="+nam+"&months="+thang,true);
	xmlhttp.send();
}
</script>
<form id="f_user_sa_pw" name="f_user_sa_pw" method="post" action="">
<div id="contains">
	<div class="title" style="padding-top: 5px;font-weight: bold;"><?php echo $l_menu_privateinfo;?> &rarr; <?php echo $l_working_spreadsheet;?> </div>
	<div class="content_code">
		<div class="approval-right">
			<div style="width:820px;border: 1px solid silver; padding: 10px 0; margin-bottom: 30px; background:white">
				<table width="820px" style="padding:0 10px">
					<tr>
						<td><b><?php echo $l_month?></b> </td>
						<td><b><?php echo $l_year?></b> </td>
						<td></td>
					</tr>
					<tr>
						<td width="80px">
							<select style="width:50px;height:24px;font-size:12px;" id="months" name="months">
								<?php for($i=1;$i<=12;$i++){?>
									<option value="<?=$i?>"  
										<?php 
											if($i==$_REQUEST['months']){
												?>
												selected="selected"
												<?php 
											}
										?>
									>
										<?php echo $i?>
									</option>
								<?php }?>
							</select> 
						</td>
						<td width="130px">
							<select style="width:100px;height:24px;font-size:12px;" id="years" name="years">
								<?php for($j=2012;$j<=$ktdate[year];$j++){?>
									<option value="<?=$j?>" 
										<?php 
											if($j==$_REQUEST['years']){
												?>
												selected="selected"
												<?php 
											}
										?>
									>
										<?php echo $j?>
									</option>
								<?php }?>
							</select>
						</td>
						<td align="left">
							<input onclick="view();" type="button" name="btview" value="<?php echo $l_View?>"  class="btnupbg btnupload" />
						</td>
					</tr>
				</table>
			</div>
			<div id="viewbody" >
			<table style="width: 100%;" class="rf-dt" id="checktimes">
				<tr>
					<td class="rf-dt-shdr-c" width="10px"><?=$l_no?></td>
					<td class="rf-dt-shdr-c" width="15%"><?=$l_employee_name?></td>
					<td class="rf-dt-shdr-c" width="5%"><?=$l_code?></td>
					<td class="rf-dt-shdr-c" width="5%"><?=$l_thu?></td>
					<td class="rf-dt-shdr-c" width="10%"><?=$l_date?></td>
					<td class="rf-dt-shdr-c" width="5%"><?=$l_timecheckin?></td>
					<td class="rf-dt-shdr-c" width="5%"><?=$l_timecheckout?></td>
					<td class="rf-dt-shdr-c" width="5%"><?=$l_late?></td>
					<td class="rf-dt-shdr-c" width="5%"><?=$l_comebackearly?></td>
					<td class="rf-dt-shdr-c" width="5%"><?=$l_half_dayoff?></td>
					<td class="rf-dt-shdr-c" width="5%"><?=$l_all_dayoff?></td>
					<td class="rf-dt-shdr-c" width="5%"><?=$l_overtime?></td>
					<td class="rf-dt-shdr-c" width="15%"><?=$l_note?></td>
					<td class="rf-dt-shdr-c" width="15%"><?=$l_update_information?></td>
				</tr>
				<?php 
				$sql="select em.IDEmployee as emid,
					em.FullName as emname,
					ct.id,
					ct.employeeID,
					upsuser.FullName as upname ,
					cruser.FullName as crname ,
					ct.employeeName,ct.time_work,
					ct.time_in,ct.time_out,
					ct.is_late,
					ct.is_comeback_early,
					ct.half_day_off,
					ct.all_day_off,
					ct.overtime,
					ct.note,
					ct.user_create,ct.createDate,
					ct.user_update,
					ct.update_date,ct.`status` as stct   
				from sa_check_time ct left join employee em on ct.employeeID = em.EmployeeCode 
				left join  employee upsuser on upsuser.IDEmployee = ct.user_update 
				left join employee cruser on cruser.IDEmployee = ct.user_create 
				where ct.`status`!=1 and ( month(ct.time_work)='".$_REQUEST['months']."' 
				and year(ct.time_work) = '".$_REQUEST['years']."' ) 
				and em.IDEmployee='".$_SESSION['IDEmployee']."' order by ct.employeeID,ct.time_work asc";
				$list = mysql_query($sql);
				if(mysql_num_rows($list)>0){
						$i=1;
					while($row = mysql_fetch_array($list)){
						$thu=getWday($row[time_work]);
					if($thu==6 || $thu==0){
					?>
					<tr style="background:#ccffcc;text-align:center;" >
					<?php 
					}else{
					?>
					<tr  style="text-align:center;">
					<?php 
					}
					?>
						<td class="rf-dt-c" width="10px"><?=$i?></td>
						<td class="rf-dt-c" width="15%"><?=$row[emname]?></td>
						<td class="rf-dt-c" width="5%"><?=$row[employeeID]?></td>
						<td class="rf-dt-c" width="5%"><?=$mthu[$thu]?></td>
						<td class="rf-dt-c" width="10%"><?=$row[time_work]?></td>
						<td class="rf-dt-c" width="5%"><?=$row[time_in]?></td>
						<td class="rf-dt-c" width="5%"><?=$row[time_out]?></td>
						<?php 
							if ($row[is_late] != '0'){
								echo '<td class="rf-dt-c" style="font-weight:bold;background:orange;text-align:center;">X</td>';
							}else{
								echo '<td class="rf-dt-c"></td>';
							}
							

							if ($row[is_comeback_early] != '0'){
								echo '<td class="rf-dt-c" style="font-weight:bold;background:yellow;text-align:center;">X</td>';
							}else{
								echo '<td class="rf-dt-c"></td>';
							}

							if ($row[half_day_off] != '0') {
								echo '<td class="rf-dt-c" style="font-weight:bold;background:pink;text-align:center;">X</td>';
							}else{
								echo '<td class="rf-dt-c"></td>';
							}

							if ($row[all_day_off] != '0'){
								echo '<td class="rf-dt-c" style="font-weight:bold;background:red;text-align:center;">X</td>';
							}else{
								echo '<td class="rf-dt-c"></td>';
							}

							if ($row[overtime] != '0') {
								echo '<td class="rf-dt-c" style="font-weight:bold;background:green;text-align:center;">X</td>';
							}else{
								echo '<td class="rf-dt-c"></td>';
							}
						?>
						<td class="rf-dt-c" width="15%"><?=$row[note]?></td>
						<td class="rf-dt-c" width="15%">
						<?php 
						if($row[user_update]==""){
							echo $row[crname]."<br>".$row[createDate];
						}else{
							echo $row[upname]."<br>".$row[update_date];
						}
						?>
						</td>
					</tr>
					<?php 
						$i++;
					}
				}else{
					?>
					<tr><td colspan="14" style="height:24px;valign:middle;padding-left:30px;"><?php echo $l_list_emplty; ?></td></tr>
					<?php 
				}
				?>
			</table>
			</div>
			<br><br>
		</div>
	</div>
</div>
</form>